package next.fire.spinus.logx.provider.aliyun.conf;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by daibing on 2020/9/15.
 */
public class AliyunLogConfigHolder {
    private static final AliyunLogConfigHolder INSTANCE = new AliyunLogConfigHolder();
    private final ConcurrentMap<String, AliyunLogConfig> configMap = new ConcurrentHashMap<>(1);

    public static AliyunLogConfigHolder get() {
        return INSTANCE;
    }

    public AliyunLogConfig select(String logStoreCode) {
        return configMap.get(logStoreCode);
    }

    public void reload(List<AliyunLogConfig> aliyunLogConfigList) {
        synchronized (configMap) {
            configMap.clear();
            for (AliyunLogConfig aliyunLogConfig : aliyunLogConfigList) {
                configMap.put(aliyunLogConfig.getLogStoreCode(), aliyunLogConfig);
            }
        }
    }

}
